<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>prencar: D:/Workspace/Arduino/prencar/Move.cpp Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  <td id="projectlogo"><img alt="Logo" src="prencar.png"/></td>
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">prencar
   &#160;<span id="projectnumber">1</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.8.0 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('_move_8cpp.html','');
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">D:/Workspace/Arduino/prencar/Move.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_move_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include &quot;Arduino.h&quot;</span>
<a name="l00002"></a>00002 <span class="preprocessor">#include &quot;<a class="code" href="_move_8h.html">Move.h</a>&quot;</span>
<a name="l00003"></a>00003 <span class="preprocessor">#include &quot;<a class="code" href="_configuration_8h.html">Configuration.h</a>&quot;</span>
<a name="l00004"></a>00004 <span class="preprocessor">#include &quot;<a class="code" href="_communication_8h.html">Communication.h</a>&quot;</span>
<a name="l00005"></a>00005 
<a name="l00006"></a>00006 <a class="code" href="class_move.html">Move</a> <a class="code" href="class_move.html#a1ce3157933da403944e754b380365c93" title="Static reference to the singleton object.">Move::_instance</a>; 
<a name="l00007"></a>00007 <span class="keywordtype">boolean</span> <a class="code" href="class_move.html#ab5a52d3f029707c767ef27a44fa5269a">Move::_instanceCreated</a> = <span class="keyword">false</span>;
<a name="l00008"></a>00008 
<a name="l00013"></a><a class="code" href="class_move.html#a5b53cfa443fe4fe0f1b96f9b3afc4850">00013</a> <a class="code" href="class_move.html">Move</a>* <a class="code" href="class_move.html#a5b53cfa443fe4fe0f1b96f9b3afc4850">Move::getInstance</a>()
<a name="l00014"></a>00014 {
<a name="l00015"></a>00015   <span class="keywordflow">if</span> ( !<a class="code" href="class_move.html#ab5a52d3f029707c767ef27a44fa5269a">_instanceCreated</a> ){
<a name="l00016"></a>00016     <a class="code" href="class_move.html#a1ce3157933da403944e754b380365c93" title="Static reference to the singleton object.">_instance</a> = <a class="code" href="class_move.html#a4b1acc3a67d30c385ad9a6000526393a">Move</a>();
<a name="l00017"></a>00017     <a class="code" href="class_move.html#ab5a52d3f029707c767ef27a44fa5269a">_instanceCreated</a> = <span class="keyword">true</span>;
<a name="l00018"></a>00018 
<a name="l00019"></a>00019     <span class="comment">//do the configuration stuff so that a call to begin() from the outside of the</span>
<a name="l00020"></a>00020     <span class="comment">//class is not necessary</span>
<a name="l00021"></a>00021     <a class="code" href="class_move.html#a1ce3157933da403944e754b380365c93" title="Static reference to the singleton object.">_instance</a>.<a class="code" href="class_move.html#afcff6c5d4fd9e58382ee01d6270f4707">begin</a>();
<a name="l00022"></a>00022   }
<a name="l00023"></a>00023   <span class="keywordflow">return</span> &amp;<a class="code" href="class_move.html#a1ce3157933da403944e754b380365c93" title="Static reference to the singleton object.">_instance</a>;
<a name="l00024"></a>00024 }
<a name="l00025"></a>00025 
<a name="l00026"></a>00026 
<a name="l00030"></a><a class="code" href="class_move.html#a4b1acc3a67d30c385ad9a6000526393a">00030</a> <a class="code" href="class_move.html#a4b1acc3a67d30c385ad9a6000526393a">Move::Move</a>()
<a name="l00031"></a>00031 {
<a name="l00032"></a>00032 
<a name="l00033"></a>00033 }
<a name="l00034"></a>00034 
<a name="l00043"></a><a class="code" href="class_move.html#afcff6c5d4fd9e58382ee01d6270f4707">00043</a> <span class="keywordtype">void</span> <a class="code" href="class_move.html#afcff6c5d4fd9e58382ee01d6270f4707">Move::begin</a>(){
<a name="l00044"></a>00044   <a class="code" href="class_move.html#ad5c8392b7540a9b46adf66918ef83fdb" title="The reference to the configuration class.">_conf</a> = <a class="code" href="class_move.html#a5b53cfa443fe4fe0f1b96f9b3afc4850">Configuration::getInstance</a>();
<a name="l00045"></a>00045   <a class="code" href="class_move.html#ae9e6d0860fc8dcf67798b19b961044cc" title="The reference to the serial communication class.">_com</a> = <a class="code" href="class_move.html#a5b53cfa443fe4fe0f1b96f9b3afc4850">Communication::getInstance</a>();
<a name="l00046"></a>00046 
<a name="l00047"></a>00047   <a class="code" href="class_move.html#a25f061becd68304548bad61fad7550b4">_pwmLeftPin</a> = <a class="code" href="class_move.html#ad5c8392b7540a9b46adf66918ef83fdb" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#aecc6c34b834bb9adb42d5f8c7314cd9c">getMovePwmLeftPin</a>();
<a name="l00048"></a>00048   <a class="code" href="class_move.html#adf25d07750cdd6f8ac4938cf82165296">_pwmRightPin</a> = <a class="code" href="class_move.html#ad5c8392b7540a9b46adf66918ef83fdb" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a156dc7d1360c8e70c7aba5eb20481afa">getMovePwmRightPin</a>();
<a name="l00049"></a>00049   <a class="code" href="class_move.html#a764f1ffe93f4a0793257351fdc1297eb">_modeFirstLeftPin</a> = <a class="code" href="class_move.html#ad5c8392b7540a9b46adf66918ef83fdb" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#aa1599159aa8233fe3f974fb2e51129e4">getMoveModeFirstLeftPin</a>();
<a name="l00050"></a>00050   <a class="code" href="class_move.html#ac74fa5cde8e507bd53fa47adfa80c19f">_modeSecondLeftPin</a> = <a class="code" href="class_move.html#ad5c8392b7540a9b46adf66918ef83fdb" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a4d1252f0afd9ebb35cc7f38a769fdeff">getMoveModeSecondLeftPin</a>();
<a name="l00051"></a>00051   <a class="code" href="class_move.html#acce4bc3657e0c5e0b9e0360306dcb1ad">_modeFirstRightPin</a> = <a class="code" href="class_move.html#ad5c8392b7540a9b46adf66918ef83fdb" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a9bf200a445b05745a678d18e46ca446d">getMoveModeFirstRightPin</a>();
<a name="l00052"></a>00052   <a class="code" href="class_move.html#a5bebefe9530ab54b6de73aa8cf08c477">_modeSecondRightPin</a> = <a class="code" href="class_move.html#ad5c8392b7540a9b46adf66918ef83fdb" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a2c95181edbee124c040f5db52c15fdb6">getMoveModeSecondRightPin</a>();
<a name="l00053"></a>00053 
<a name="l00054"></a>00054   pinMode(<a class="code" href="class_move.html#a25f061becd68304548bad61fad7550b4">_pwmLeftPin</a>, OUTPUT);
<a name="l00055"></a>00055   pinMode(<a class="code" href="class_move.html#adf25d07750cdd6f8ac4938cf82165296">_pwmRightPin</a>, OUTPUT);
<a name="l00056"></a>00056   pinMode(<a class="code" href="class_move.html#a764f1ffe93f4a0793257351fdc1297eb">_modeFirstLeftPin</a>, OUTPUT);
<a name="l00057"></a>00057   pinMode(<a class="code" href="class_move.html#ac74fa5cde8e507bd53fa47adfa80c19f">_modeSecondLeftPin</a>, OUTPUT);
<a name="l00058"></a>00058   pinMode(<a class="code" href="class_move.html#acce4bc3657e0c5e0b9e0360306dcb1ad">_modeFirstRightPin</a>, OUTPUT);
<a name="l00059"></a>00059   pinMode(<a class="code" href="class_move.html#a5bebefe9530ab54b6de73aa8cf08c477">_modeSecondRightPin</a>, OUTPUT);
<a name="l00060"></a>00060 }
<a name="l00061"></a>00061 
<a name="l00065"></a><a class="code" href="class_move.html#a237261f2dd8fc115129f0ba998f13183">00065</a> <span class="keywordtype">void</span> <a class="code" href="class_move.html#a237261f2dd8fc115129f0ba998f13183">Move::performFastStop</a>()
<a name="l00066"></a>00066 {
<a name="l00067"></a>00067   <a class="code" href="class_move.html#ae9e6d0860fc8dcf67798b19b961044cc" title="The reference to the serial communication class.">_com</a>-&gt;<a class="code" href="class_communication.html#a8679b3cb7ceef5527faa24454ce0f18a">send</a>(60);
<a name="l00068"></a>00068   digitalWrite(<a class="code" href="class_move.html#a764f1ffe93f4a0793257351fdc1297eb">_modeFirstLeftPin</a>, HIGH);
<a name="l00069"></a>00069   digitalWrite(<a class="code" href="class_move.html#ac74fa5cde8e507bd53fa47adfa80c19f">_modeSecondLeftPin</a>, HIGH);
<a name="l00070"></a>00070   digitalWrite(<a class="code" href="class_move.html#acce4bc3657e0c5e0b9e0360306dcb1ad">_modeFirstRightPin</a>, HIGH);
<a name="l00071"></a>00071   digitalWrite(<a class="code" href="class_move.html#a5bebefe9530ab54b6de73aa8cf08c477">_modeSecondRightPin</a>, HIGH);
<a name="l00072"></a>00072 }
<a name="l00073"></a>00073 
<a name="l00083"></a><a class="code" href="class_move.html#a9c5dc5c3a98abece0c2f40085c3601be">00083</a> <span class="keywordtype">void</span> <a class="code" href="class_move.html#a9c5dc5c3a98abece0c2f40085c3601be">Move::controlMotors</a>(<a class="code" href="_move_8h.html#a4d576498f070661245f38f5f34d34f02">TMotorDirection</a> dirLeftMotor, <span class="keywordtype">int</span> speedLeftMotor, <a class="code" href="_move_8h.html#a4d576498f070661245f38f5f34d34f02">TMotorDirection</a> dirRightMotor, <span class="keywordtype">int</span> speedRightMotor){
<a name="l00084"></a>00084   <span class="keywordflow">if</span>(speedLeftMotor &gt; 255) speedLeftMotor = 255;
<a name="l00085"></a>00085   <span class="keywordflow">if</span>(speedRightMotor &gt; 255) speedRightMotor = 255;
<a name="l00086"></a>00086 
<a name="l00087"></a>00087   <span class="keywordflow">if</span>(speedLeftMotor &lt; 0) speedLeftMotor = 0;
<a name="l00088"></a>00088   <span class="keywordflow">if</span>(speedRightMotor &lt; 0) speedRightMotor = 0;
<a name="l00089"></a>00089 
<a name="l00090"></a>00090   <a class="code" href="class_move.html#ada9423f195c9ee65b5448fcaabb96877" title="current speed of left motor (pwm value 0-255)">_speedLeft</a> = speedLeftMotor;
<a name="l00091"></a>00091   <a class="code" href="class_move.html#a13362460beddf2de2415d51f3ed70841" title="current speed of right motor (pwm value 0-255)">_speedRight</a> = speedRightMotor;
<a name="l00092"></a>00092   
<a name="l00093"></a>00093   <span class="keywordtype">int</span> parameters[4];
<a name="l00094"></a>00094   parameters[0] = <a class="code" href="class_move.html#ada9423f195c9ee65b5448fcaabb96877" title="current speed of left motor (pwm value 0-255)">_speedLeft</a>;
<a name="l00095"></a>00095   parameters[1] = dirLeftMotor;
<a name="l00096"></a>00096   parameters[2] = <a class="code" href="class_move.html#a13362460beddf2de2415d51f3ed70841" title="current speed of right motor (pwm value 0-255)">_speedRight</a>;
<a name="l00097"></a>00097   parameters[3] = dirRightMotor;
<a name="l00098"></a>00098 
<a name="l00099"></a>00099   <a class="code" href="class_move.html#ae9e6d0860fc8dcf67798b19b961044cc" title="The reference to the serial communication class.">_com</a>-&gt;<a class="code" href="class_communication.html#a8679b3cb7ceef5527faa24454ce0f18a">send</a>(58, parameters, 4);
<a name="l00100"></a>00100   
<a name="l00101"></a>00101   analogWrite(<a class="code" href="class_move.html#a25f061becd68304548bad61fad7550b4">_pwmLeftPin</a>, <a class="code" href="class_move.html#ada9423f195c9ee65b5448fcaabb96877" title="current speed of left motor (pwm value 0-255)">_speedLeft</a>);
<a name="l00102"></a>00102   <a class="code" href="class_move.html#af6b1197771f0540b0becc4117d8d272f">setLeftMotorDirection</a>(dirLeftMotor);
<a name="l00103"></a>00103   analogWrite(<a class="code" href="class_move.html#adf25d07750cdd6f8ac4938cf82165296">_pwmRightPin</a>, <a class="code" href="class_move.html#a13362460beddf2de2415d51f3ed70841" title="current speed of right motor (pwm value 0-255)">_speedRight</a>);
<a name="l00104"></a>00104   <a class="code" href="class_move.html#a06e67dafd581bbd086da404a90c4eeec">setRightMotorDirection</a>(dirRightMotor);
<a name="l00105"></a>00105 }
<a name="l00106"></a>00106 
<a name="l00111"></a><a class="code" href="class_move.html#af6b1197771f0540b0becc4117d8d272f">00111</a> <span class="keywordtype">void</span> <a class="code" href="class_move.html#af6b1197771f0540b0becc4117d8d272f">Move::setLeftMotorDirection</a>(<span class="keyword">enum</span> <a class="code" href="_move_8h.html#a4d576498f070661245f38f5f34d34f02">TMotorDirection</a> dir){
<a name="l00112"></a>00112   <span class="keywordtype">int</span> dirCode;
<a name="l00113"></a>00113   <a class="code" href="class_move.html#a280c47406bd7e652c35c7900ca8c745b" title="current direction of left motor">_dirLeftMotor</a> = dir;
<a name="l00114"></a>00114   <span class="keywordflow">if</span>(dir == <a class="code" href="_move_8h.html#a4d576498f070661245f38f5f34d34f02ac692b9392597318793a64449c874c723" title="Phase out the motor. The power is taken away from the motor but the car can roll a couple of centimer...">phaseOut</a>){
<a name="l00115"></a>00115     digitalWrite(<a class="code" href="class_move.html#a764f1ffe93f4a0793257351fdc1297eb">_modeFirstLeftPin</a>, LOW);
<a name="l00116"></a>00116     digitalWrite(<a class="code" href="class_move.html#ac74fa5cde8e507bd53fa47adfa80c19f">_modeSecondLeftPin</a>, LOW);
<a name="l00117"></a>00117     dirCode = 0;
<a name="l00118"></a>00118   }
<a name="l00119"></a>00119   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(dir == <a class="code" href="_move_8h.html#a4d576498f070661245f38f5f34d34f02a726a0af5164861adac8c015a742dcf21" title="The motor rotates forward.">forward</a>){
<a name="l00120"></a>00120     digitalWrite(<a class="code" href="class_move.html#a764f1ffe93f4a0793257351fdc1297eb">_modeFirstLeftPin</a>, HIGH);
<a name="l00121"></a>00121     digitalWrite(<a class="code" href="class_move.html#ac74fa5cde8e507bd53fa47adfa80c19f">_modeSecondLeftPin</a>, LOW);
<a name="l00122"></a>00122     dirCode = 1;
<a name="l00123"></a>00123   }
<a name="l00124"></a>00124   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(dir == <a class="code" href="_move_8h.html#a4d576498f070661245f38f5f34d34f02ab0b7e8cfed43da5fcfd380964736fadc" title="The motor rotates backward.">backwards</a>){
<a name="l00125"></a>00125     digitalWrite(<a class="code" href="class_move.html#a764f1ffe93f4a0793257351fdc1297eb">_modeFirstLeftPin</a>, LOW);
<a name="l00126"></a>00126     digitalWrite(<a class="code" href="class_move.html#ac74fa5cde8e507bd53fa47adfa80c19f">_modeSecondLeftPin</a>, HIGH);
<a name="l00127"></a>00127     dirCode = 2;
<a name="l00128"></a>00128   }
<a name="l00129"></a>00129   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(dir == <a class="code" href="_move_8h.html#a4d576498f070661245f38f5f34d34f02a25b14d88f35aee0f0638e63994a6a810" title="The motor is stopped immediately. This is done by shortly giving power in the other direction...">fastStop</a>){
<a name="l00130"></a>00130     digitalWrite(<a class="code" href="class_move.html#a764f1ffe93f4a0793257351fdc1297eb">_modeFirstLeftPin</a>, HIGH);
<a name="l00131"></a>00131     digitalWrite(<a class="code" href="class_move.html#ac74fa5cde8e507bd53fa47adfa80c19f">_modeSecondLeftPin</a>, HIGH);
<a name="l00132"></a>00132     dirCode = 3;
<a name="l00133"></a>00133   }
<a name="l00134"></a>00134 
<a name="l00135"></a>00135   <span class="comment">//_com-&gt;send(51, dirCode);</span>
<a name="l00136"></a>00136 }
<a name="l00137"></a>00137 
<a name="l00142"></a><a class="code" href="class_move.html#a06e67dafd581bbd086da404a90c4eeec">00142</a> <span class="keywordtype">void</span> <a class="code" href="class_move.html#a06e67dafd581bbd086da404a90c4eeec">Move::setRightMotorDirection</a>(<a class="code" href="_move_8h.html#a4d576498f070661245f38f5f34d34f02">TMotorDirection</a> dir){
<a name="l00143"></a>00143   <span class="keywordtype">int</span> dirCode;
<a name="l00144"></a>00144   <a class="code" href="class_move.html#ace1041b9df6281fdc960013ccac5c32a" title="current direction of right motor">_dirRightMotor</a> = dir;
<a name="l00145"></a>00145   <span class="keywordflow">if</span>(dir == <a class="code" href="_move_8h.html#a4d576498f070661245f38f5f34d34f02ac692b9392597318793a64449c874c723" title="Phase out the motor. The power is taken away from the motor but the car can roll a couple of centimer...">phaseOut</a>){
<a name="l00146"></a>00146     digitalWrite(<a class="code" href="class_move.html#acce4bc3657e0c5e0b9e0360306dcb1ad">_modeFirstRightPin</a>, LOW);
<a name="l00147"></a>00147     digitalWrite(<a class="code" href="class_move.html#a5bebefe9530ab54b6de73aa8cf08c477">_modeSecondRightPin</a>, LOW);
<a name="l00148"></a>00148     dirCode = 0;
<a name="l00149"></a>00149   }
<a name="l00150"></a>00150   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(dir == <a class="code" href="_move_8h.html#a4d576498f070661245f38f5f34d34f02a726a0af5164861adac8c015a742dcf21" title="The motor rotates forward.">forward</a>){
<a name="l00151"></a>00151     digitalWrite(<a class="code" href="class_move.html#acce4bc3657e0c5e0b9e0360306dcb1ad">_modeFirstRightPin</a>, HIGH);
<a name="l00152"></a>00152     digitalWrite(<a class="code" href="class_move.html#a5bebefe9530ab54b6de73aa8cf08c477">_modeSecondRightPin</a>, LOW);
<a name="l00153"></a>00153     dirCode = 1;
<a name="l00154"></a>00154   }
<a name="l00155"></a>00155   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(dir == <a class="code" href="_move_8h.html#a4d576498f070661245f38f5f34d34f02ab0b7e8cfed43da5fcfd380964736fadc" title="The motor rotates backward.">backwards</a>){
<a name="l00156"></a>00156     digitalWrite(<a class="code" href="class_move.html#acce4bc3657e0c5e0b9e0360306dcb1ad">_modeFirstRightPin</a>, LOW);
<a name="l00157"></a>00157     digitalWrite(<a class="code" href="class_move.html#a5bebefe9530ab54b6de73aa8cf08c477">_modeSecondRightPin</a>, HIGH);
<a name="l00158"></a>00158     dirCode = 2;
<a name="l00159"></a>00159   }
<a name="l00160"></a>00160   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(dir == <a class="code" href="_move_8h.html#a4d576498f070661245f38f5f34d34f02a25b14d88f35aee0f0638e63994a6a810" title="The motor is stopped immediately. This is done by shortly giving power in the other direction...">fastStop</a>){
<a name="l00161"></a>00161     digitalWrite(<a class="code" href="class_move.html#acce4bc3657e0c5e0b9e0360306dcb1ad">_modeFirstRightPin</a>, HIGH);
<a name="l00162"></a>00162     digitalWrite(<a class="code" href="class_move.html#a5bebefe9530ab54b6de73aa8cf08c477">_modeSecondRightPin</a>, HIGH);
<a name="l00163"></a>00163     dirCode = 3;
<a name="l00164"></a>00164   }
<a name="l00165"></a>00165 
<a name="l00166"></a>00166   <span class="comment">//_com-&gt;send(52, dirCode);</span>
<a name="l00167"></a>00167 }
<a name="l00168"></a>00168 
<a name="l00175"></a><a class="code" href="class_move.html#a0d9285d4088aa0c6fdab04f0a0e5df2c">00175</a> <span class="keywordtype">void</span> <a class="code" href="class_move.html#a0d9285d4088aa0c6fdab04f0a0e5df2c">Move::changeMotorSpeed</a>(<span class="keywordtype">int</span> changeLeftMotor, <span class="keywordtype">int</span> changeRightMotor){
<a name="l00176"></a>00176   <span class="keywordtype">int</span> parameters[6];
<a name="l00177"></a>00177   parameters[0] = <a class="code" href="class_move.html#ada9423f195c9ee65b5448fcaabb96877" title="current speed of left motor (pwm value 0-255)">_speedLeft</a>;
<a name="l00178"></a>00178   parameters[1] = changeLeftMotor;
<a name="l00179"></a>00179   parameters[3] = <a class="code" href="class_move.html#a13362460beddf2de2415d51f3ed70841" title="current speed of right motor (pwm value 0-255)">_speedRight</a>;
<a name="l00180"></a>00180   parameters[4] = changeRightMotor;
<a name="l00181"></a>00181 
<a name="l00182"></a>00182   parameters[2] = <a class="code" href="class_move.html#ada9423f195c9ee65b5448fcaabb96877" title="current speed of left motor (pwm value 0-255)">_speedLeft</a> + changeLeftMotor;
<a name="l00183"></a>00183   parameters[5] = <a class="code" href="class_move.html#a13362460beddf2de2415d51f3ed70841" title="current speed of right motor (pwm value 0-255)">_speedRight</a> + changeRightMotor;
<a name="l00184"></a>00184 
<a name="l00185"></a>00185   <a class="code" href="class_move.html#ae9e6d0860fc8dcf67798b19b961044cc" title="The reference to the serial communication class.">_com</a>-&gt;<a class="code" href="class_communication.html#a8679b3cb7ceef5527faa24454ce0f18a">send</a>(53, parameters, 6);
<a name="l00186"></a>00186 
<a name="l00187"></a>00187   <a class="code" href="class_move.html#a9c5dc5c3a98abece0c2f40085c3601be">controlMotors</a>(<a class="code" href="class_move.html#a280c47406bd7e652c35c7900ca8c745b" title="current direction of left motor">_dirLeftMotor</a>, parameters[2], <a class="code" href="class_move.html#ace1041b9df6281fdc960013ccac5c32a" title="current direction of right motor">_dirRightMotor</a>, parameters[5]);
<a name="l00188"></a>00188 }
<a name="l00189"></a>00189 
<a name="l00198"></a><a class="code" href="class_move.html#a5ba1c7d78d6a067bc3cfa5f9cdca921f">00198</a> <span class="keywordtype">void</span> <a class="code" href="class_move.html#a5ba1c7d78d6a067bc3cfa5f9cdca921f">Move::changeMotorSpeedBasedOnInitialSpeed</a>(<span class="keywordtype">int</span> changeLeftMotor, <span class="keywordtype">int</span> changeRightMotor){
<a name="l00199"></a>00199   <span class="keywordtype">int</span> parameters[6];
<a name="l00200"></a>00200   parameters[0] = <a class="code" href="class_move.html#ada9423f195c9ee65b5448fcaabb96877" title="current speed of left motor (pwm value 0-255)">_speedLeft</a>;
<a name="l00201"></a>00201   parameters[1] = changeLeftMotor;
<a name="l00202"></a>00202   parameters[3] = <a class="code" href="class_move.html#a13362460beddf2de2415d51f3ed70841" title="current speed of right motor (pwm value 0-255)">_speedRight</a>;
<a name="l00203"></a>00203   parameters[4] = changeRightMotor;
<a name="l00204"></a>00204 
<a name="l00205"></a>00205   parameters[2] = <a class="code" href="class_move.html#ad5c8392b7540a9b46adf66918ef83fdb" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#a24e118088874b8f9d56bcaf245f1461d" title="The initial speed of the left motor when the parcours starts (0-255).">lineFollowInitialSpeedLeft</a> + changeLeftMotor;
<a name="l00206"></a>00206   parameters[5] = <a class="code" href="class_move.html#ad5c8392b7540a9b46adf66918ef83fdb" title="The reference to the configuration class.">_conf</a>-&gt;<a class="code" href="class_configuration.html#aabc113e529eb659768ca98f15d3952a3" title="The initial speed of the left motor when the parcours starts (0-255).">lineFollowInitialSpeedRight</a> + changeRightMotor;
<a name="l00207"></a>00207 
<a name="l00208"></a>00208   <a class="code" href="class_move.html#ae9e6d0860fc8dcf67798b19b961044cc" title="The reference to the serial communication class.">_com</a>-&gt;<a class="code" href="class_communication.html#a8679b3cb7ceef5527faa24454ce0f18a">send</a>(53, parameters, 6);
<a name="l00209"></a>00209 
<a name="l00210"></a>00210   <a class="code" href="class_move.html#a9c5dc5c3a98abece0c2f40085c3601be">controlMotors</a>(<a class="code" href="class_move.html#a280c47406bd7e652c35c7900ca8c745b" title="current direction of left motor">_dirLeftMotor</a>, parameters[2], <a class="code" href="class_move.html#ace1041b9df6281fdc960013ccac5c32a" title="current direction of right motor">_dirRightMotor</a>, parameters[5]);
<a name="l00211"></a>00211 }
<a name="l00212"></a>00212 
<a name="l00218"></a><a class="code" href="class_move.html#a8dfdbb462ec42c3a2b4682db5cd5c692">00218</a> <span class="keywordtype">void</span> <a class="code" href="class_move.html#a8dfdbb462ec42c3a2b4682db5cd5c692">Move::equalizeMotorsSpeed</a>(){
<a name="l00219"></a>00219   <span class="comment">//calculating the average speed. we don&#39;t care of misscalculation of 0.5</span>
<a name="l00220"></a>00220   byte averageSpeed = (byte)((((<span class="keywordtype">int</span>)<a class="code" href="class_move.html#ada9423f195c9ee65b5448fcaabb96877" title="current speed of left motor (pwm value 0-255)">_speedLeft</a>) + ((<span class="keywordtype">int</span>)<a class="code" href="class_move.html#a13362460beddf2de2415d51f3ed70841" title="current speed of right motor (pwm value 0-255)">_speedRight</a>)) / 2);
<a name="l00221"></a>00221 
<a name="l00222"></a>00222   <span class="keywordtype">int</span> parameters[] = {
<a name="l00223"></a>00223     <a class="code" href="class_move.html#ada9423f195c9ee65b5448fcaabb96877" title="current speed of left motor (pwm value 0-255)">_speedLeft</a>, <a class="code" href="class_move.html#a13362460beddf2de2415d51f3ed70841" title="current speed of right motor (pwm value 0-255)">_speedRight</a>, averageSpeed
<a name="l00224"></a>00224   };
<a name="l00225"></a>00225 
<a name="l00226"></a>00226   <a class="code" href="class_move.html#ae9e6d0860fc8dcf67798b19b961044cc" title="The reference to the serial communication class.">_com</a>-&gt;<a class="code" href="class_communication.html#a8679b3cb7ceef5527faa24454ce0f18a">send</a>(54, parameters, 3);
<a name="l00227"></a>00227   _speedLeft = averageSpeed;
<a name="l00228"></a>00228   _speedRight = averageSpeed;
<a name="l00229"></a>00229 
<a name="l00230"></a>00230   analogWrite(<a class="code" href="class_move.html#a25f061becd68304548bad61fad7550b4">_pwmLeftPin</a>, _speedLeft);
<a name="l00231"></a>00231   analogWrite(<a class="code" href="class_move.html#adf25d07750cdd6f8ac4938cf82165296">_pwmRightPin</a>, _speedRight);
<a name="l00232"></a>00232 }
<a name="l00233"></a>00233 
<a name="l00234"></a>00234 
<a name="l00235"></a>00235 
<a name="l00236"></a>00236 
<a name="l00237"></a>00237 
</pre></div></div><!-- contents -->
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="_move_8cpp.html">Move.cpp</a>      </li>

    <li class="footer">Generated on Thu Apr 26 2012 09:42:56 for prencar by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.0 </li>
   </ul>
 </div>


</body>
</html>
